package com.schoolcloud.social.controller.forum;


import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.social.entity.SocPostTags;
import com.schoolcloud.social.query.PostTagQuery;
import com.schoolcloud.social.service.SocPostTagsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RequiredArgsConstructor
@RestController
@RequestMapping("/social/post/tag")
public class SocPostTagController {
    private final SocPostTagsService postTagsService;

    @PostMapping
    public R addPostTag(@RequestBody SocPostTags tag) {
        tag.setCreateTime(LocalDateTime.now());
        postTagsService.save(tag);
        return R.ok();
    }

    @DeleteMapping("/{tagId}")
    public R deletePostTag(@PathVariable Integer tagId) {
        postTagsService.removeById(tagId);
        return R.ok();
    }
    @GetMapping("/page")
    public R<PageDTO<SocPostTags>> getPostTagPage(PostTagQuery query) {
       PageDTO<SocPostTags> page = postTagsService.getPostTagPage(query);
        return R.ok(page);
    }

    @PutMapping
    public R updatePostTag(@RequestBody SocPostTags tag) {
        postTagsService.updateById(tag);
        return R.ok();
    }
}
